package com.ktjy.crm.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ktjy.crm.entity.SysUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Description
 * @Author 曹正
 * @Date 2025/1/6 17:15
 **/
@Mapper // 显式添加 @Mapper 注解
public interface UserMapper extends BaseMapper<SysUser> {
    int insert(SysUser sysUser);
    int delete(int id);
    int update(SysUser sysUser);
    // 如果确实需要自定义查询方法，可以使用 @Select 注解并指定返回类型
    @Select("SELECT * FROM sys_user WHERE usr_id = #{usrId}")
    SysUser get(int id);
    @Select("SELECT * FROM sys_user")
    List<SysUser> findAll();
    @Select("SELECT\n" +
            "            u.*,\n" +
            "            r.role_name\n" +
            "        FROM\n" +
            "            sys_user u\n" +
            "                LEFT JOIN sys_role r ON u.usr_role_id = r.role_id")
    List<SysUser> getUserListWithRoleName();
    @Select("SELECT\n" +
            "            u.*,\n" +
            "            r.role_name\n" +
            "        FROM\n" +
            "            sys_user u\n" +
            "                LEFT JOIN sys_role r ON u.usr_role_id = r.role_id\n" +
            "        WHERE\n" +
            "            u.usr_name = #{usrName}")
    SysUser getUserByUserNameWithRoleName(String usrName);
}
